import {Injectable, InjectionToken} from '@angular/core';
import {TopMenu} from '../../shared/components/scrollable-tab/scrollable-tab.component';
import {ImageSlider} from '../../shared/components/image-slider/image-slider.component';
import {Channel} from '../../shared/components/horizontal-grid/horizontal-grid.component';
import {HttpClient} from '@angular/common/http';
import {environment} from '../../../environments/environment';
import {Observable} from 'rxjs';
import {Ad, Product} from '../../shared/domain';

export const token = new InjectionToken<string>('baseUrl');

@Injectable({
  providedIn: 'root'
})
export class HomeService {
  constructor(
    private http: HttpClient
  ) {
  }

  getTabs(): Observable<TopMenu[]> {
    return this.http.get<TopMenu[]>(`${environment.baseUrl}/tabs`);
  }

  getChannels(): Observable<Channel[]> {
    return this.http.get<Channel[]>(`${environment.baseUrl}/channels`);
  }

  getBanners(): Observable<ImageSlider[]> {
    return this.http.get<ImageSlider[]>(`${environment.baseUrl}/banners`);
  }

  getAdByTab(tab: string): Observable<Ad[]> {
    return this.http.get<Ad[]>(`${environment.baseUrl}/ads`, {params: {categories_like: tab}});
  }

  getProductByTab(tab: string): Observable<Product[]> {
    return this.http.get<Product[]>(`${environment.baseUrl}/products`, {params: {categories_like: tab}});
  }
}
